package com.hjx.leetcode;

import java.util.concurrent.CountDownLatch;

/**
 * 控制线程的执行顺序
 * 解法1、CountDownLatch 实现一个等一个的效果
 */
class LeetCode_1114_solution1 {

    public CountDownLatch c2 = new CountDownLatch(1);
    public CountDownLatch c3 = new CountDownLatch(1);

    public void first(Runnable printFirst) throws InterruptedException {

        // printFirst.run() outputs "first". Do not change or remove this line.
        printFirst.run();
        //开启second
        c2.countDown();
    }

    public void second(Runnable printSecond) throws InterruptedException {
        c2.await();

        // printSecond.run() outputs "second". Do not change or remove this line.
        printSecond.run();
        //开启third
        c3.countDown();
    }

    public void third(Runnable printThird) throws InterruptedException {

        c3.await();
        // printThird.run() outputs "third". Do not change or remove this line.
        printThird.run();
    }

}
